# -*- coding: UTF-8 -*-
from utility import db_utility
from django.db import connection
class userDAO(object):

    def checkRolesUrl(username):
        pass

    def getUserInfo(self,username):
        #user = models.Users.objects.get(userName=username)
        sql="select * from roles_users where userName='%s'" % username
        result = db_utility.db_query_execute(connection,sql,'0')
        print("getUserInfo="+str(result))
<<<<<<< HEAD
        return result[0]
=======
        if result :
            return result[0]
        else:
            return {}
>>>>>>> 03b0cbb3079f9b560266e5d23952e075f9348e64

    def getUserList(self):
        sql="select * from roles_users ORDER BY userId"
        result = db_utility.db_query_execute(connection,sql,'1')
        return result
<<<<<<< HEAD

    def getGroupList(self):
        sql="select * from roles_usergroup order by groupId"
        result = db_utility.db_query_execute(connection,sql,'1')
        return result

    def getRoleList(self):
        sql="select * from roles_role order by roleId"
        result = db_utility.db_query_execute(connection,sql,'1')
        return result

=======

    def getGroupList(self):
        sql="select * from roles_usergroup order by groupId"
        result = db_utility.db_query_execute(connection,sql,'1')
        return result

    def getRoleList(self):
        sql="select * from roles_role order by roleId"
        result = db_utility.db_query_execute(connection,sql,'1')
        return result

>>>>>>> 03b0cbb3079f9b560266e5d23952e075f9348e64
    def createUser(userInfoList):
        pass

    def getUserLeftMenu(self,groupId):
        sql = "select b.url,b.classStyle,a.isdefault,b.roleName from roles_grouprolerel a,roles_role b where a.roleId = b.roleId and a.groupId=%s order by a.id" % groupId
        result = db_utility.db_query_execute(connection, sql,'0')
<<<<<<< HEAD
        print("rolesDAO.getUserLeftMenu="+str(result))
=======
>>>>>>> 03b0cbb3079f9b560266e5d23952e075f9348e64
        return result
    def getDefaultGourpUrl(self,groupId):
        sql = "select a.url from roles_role a,roles_grouprolerel b where a.roleId = b.roleId and b.groupId=%s and b.isDefault=1" % groupId
        result = db_utility.db_query_execute(connection, sql,'0')
        return result[0]